home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / perl5a1.lha / perl5alpha1 / do / ggrent < prev    next >
Encoding:
Text File  |  1992-08-15  |  1.3 KB  |  62 lines

  1. int
  2. do_ggrent(which,gimme,arglast)
  3. int which;
  4. int gimme;
  5. int *arglast;
  6. {
  7. #ifdef I_GRP
  8.     register ARRAY *ary = stack;
  9.     register int sp = arglast[0];
  10.     register char **elem;
  11.     register STR *TARG;
  12.     struct group *getgrnam();
  13.     struct group *getgrgid();
  14.     struct group *getgrent();
  15.     struct group *grent;
  16.  
  17.     if (which == O_GGRNAM) {
  18.     char *name = str_get(ary->ary_array[sp+1]);
  19.  
  20.     grent = getgrnam(name);
  21.     }
  22.     else if (which == O_GGRGID) {
  23.     int gid = (int)str_gnum(ary->ary_array[sp+1]);
  24.  
  25.     grent = getgrgid(gid);
  26.     }
  27.     else
  28.     grent = getgrent();
  29.  
  30.     if (gimme != G_ARRAY) {
  31.     astore(ary, ++sp, TARG = str_mortal(&str_undef));
  32.     if (grent) {
  33.         if (which == O_GGRNAM)
  34.         str_numset(TARG, (double)grent->gr_gid);
  35.         else
  36.         str_set(TARG, grent->gr_name);
  37.     }
  38.     return sp;
  39.     }
  40.  
  41.     if (grent) {
  42.     (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
  43.     str_set(TARG, grent->gr_name);
  44.     (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
  45.     str_set(TARG, grent->gr_passwd);
  46.     (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
  47.     str_numset(TARG, (double)grent->gr_gid);
  48.     (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
  49.     for (elem = grent->gr_mem; *elem; elem++) {
  50.         str_cat(TARG, *elem);
  51.         if (elem[1])
  52.         str_ncat(TARG," ",1);
  53.     }
  54.     }
  55.  
  56.     return sp;
  57. #else
  58.     fatal("group routines not implemented");
  59. #endif
  60. }
  61.  
  62.